package com.ndp.fb.mq.producer;

import com.ndp.fb.enums.account.AccountOperateType;
import com.ndp.fb.enums.connectionobject.EntrustConnectionObjectOperateType;
import com.ndp.fb.enums.page.PageOperateType;
import com.ndp.fb.model.fbagent.param.ApiCallBackTarget;
import com.ndp.fb.mq.api.producer.AssetsAlertProducerService;
import com.ndp.fb.mq.api.producer.RocketMqProducerService;
import com.ndp.fb.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by elvisxiong on 16/2/24.
 */
@Component
public class AssetsAlertProducerServiceImpl implements AssetsAlertProducerService {

    @Autowired
    private RocketMqProducerService rocketMqProducerService;

    @Override
    public void notificationAccountAlert(String userId, Long accountId, AccountOperateType accountOperateType) {
        ApiCallBackTarget.Target target = ApiCallBackTarget.AssetsAlert.AccountAlert;
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,String> messageMap = new HashMap<String,String>();
        messageMap.put("userId",userId);
        messageMap.put("accountId",accountId!=null?accountId.toString():null);
        messageMap.put("accountOperateType",accountOperateType!=null?accountOperateType.toString():null);
        map.put("equipment",messageMap);
        rocketMqProducerService.sendMessage(target.getModuleName(),target.getTargetType(), UUID.get(),map);
    }

    @Override
    public void notificationAppAlert(String userId, Long accountId, Long businessId, Long connectionObjectId, EntrustConnectionObjectOperateType entrustConnectionObjectOperateType) {
        ApiCallBackTarget.Target target = ApiCallBackTarget.AssetsAlert.AppAlert;
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,String> messageMap = new HashMap<String,String>();
        messageMap.put("userId",userId);
        messageMap.put("accountId",accountId!=null ? accountId.toString():null);
        messageMap.put("businessId",businessId!=null?businessId.toString():null);
        messageMap.put("connectionObjectId",connectionObjectId!=null?connectionObjectId.toString():null);
        messageMap.put("entrustConnectionObjectOperateType",entrustConnectionObjectOperateType!=null?entrustConnectionObjectOperateType.toString():null);
        map.put("equipment",messageMap);
        rocketMqProducerService.sendMessage(target.getModuleName(),target.getTargetType(), UUID.get(),map);
    }

    @Override
    public void notificationPageAlert(String userId, Long accountId, Long businessId, Long pageId, PageOperateType pageOperateType) {
        ApiCallBackTarget.Target target = ApiCallBackTarget.AssetsAlert.PageAlert;
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,String> messageMap = new HashMap<String,String>();
        messageMap.put("userId",userId);
        messageMap.put("accountId",accountId!=null?accountId.toString():null);
        messageMap.put("businessId",businessId!=null?businessId.toString():null);
        messageMap.put("pageId",pageId!=null?pageId.toString():null);
        messageMap.put("pageOperateType",pageOperateType!=null?pageOperateType.toString():null);
        map.put("equipment",messageMap);
        rocketMqProducerService.sendMessage(target.getModuleName(),target.getTargetType(), UUID.get(),map);
    }
}
